package ar.com.cema.methodology.analyzer.services.repository.impl;

import java.util.Collection;

import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import ar.com.cema.methodology.analyzer.model.MethodologyUsageStatistic;
import ar.com.cema.methodology.analyzer.model.Variable;
import ar.com.cema.methodology.analyzer.services.persistence.SimpleDAO;
import ar.com.cema.methodology.analyzer.services.repository.StatisticsRepository;

@Repository
public class StatisticsRepositoryImpl implements StatisticsRepository {

	@Autowired
	private SimpleDAO simpleDAO;

	public void setSimpleDAO(SimpleDAO simpleDAO) {
		this.simpleDAO = simpleDAO;
	}

	@Override
	@SuppressWarnings("unchecked")
	public Collection<MethodologyUsageStatistic> findStatisticsOrderyByScoreFor(Collection<Variable> variables) {
		Collection<MethodologyUsageStatistic> statistics = simpleDAO.createCriteria(MethodologyUsageStatistic.class)
															.add(Restrictions.in("id.variable", variables))
															.addOrder(Order.asc("id.variable"))
															.addOrder(Order.asc("score"))
															.list();
		return statistics;
	}
}